﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class EnemyBlood : MonoBehaviour {
    public Scrollbar m_bloodBar;
    public Monster m_enemy;
    Vector3 m_pos;
    public Monster Enemy
    {
        set { m_enemy = value; }
    }
    public void InitBloodBar()
    {
        m_bloodBar = GetComponent<Scrollbar>();
        m_bloodBar.size = m_enemy.Hp / m_enemy.MaxHp;
        m_pos = Camera.main.WorldToScreenPoint(m_enemy.Hp_Pos);
        //transform.position = new Vector2((m_pos.x - Screen.width / 2) * 800 / Screen.width, (m_pos.y - Screen.height / 2) * 600 / Screen.height);
        transform.position = m_pos;
    }
    void BloodChange()
    {
        m_bloodBar.size = m_enemy.Hp / m_enemy.MaxHp;
        m_pos = Camera.main.WorldToScreenPoint(m_enemy.Hp_Pos);
        //transform.position = new Vector2((m_pos.x - Screen.width / 2) * 800 / Screen.width, (m_pos.y - Screen.height / 2) * 600 / Screen.height);
        transform.position = m_pos;
    }
    // Use this for initialization
    void Start () {

    }
	
	// Update is called once per frame
	void Update () {
        BloodChange();
        if (m_enemy.Hp <= 0||!m_enemy.gameObject.activeSelf)
            Destroy(this.gameObject);

    }
}
